#!/bin/bash
#http://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/
#http://www.cnblogs.com/clam/archive/2012/12/17/2821684.html
#set -e #遇错退出
Err_Exit()
{
    File=$0
    Line=$1
    ExitValue=$2
    Reason=$3
    if [ "$Reason" = "" ]; then
	Reason=Unknow
    fi
    echo Error:[File:$File],[Line:$Line],[ExitValue:$ExitValue],[Reason:$Reason] 1>&2
    #exit 1
}
trap 'Err_Exit $LINENO $?' ERR

function not_exist()
{
    ls not_exist_dir
}

not_exist
not_define_function

ls ttt || Err_Exit $LINENO $? "ttt not exist"



#trap DEBUG
#trap 'echo "before execute line: [ $LINENO ] , a=$a, b=$b, c=$c"' DEBUG
#a=1
#if [ "$a" -eq 1 ]
#then
#   b=2
#else
#   b=1
#fi
#c=3
#
#echo "trap DEBUG end "

#DEBUG handle
export DEBUG=false
DEBUG()
{
    if [ "$DEBUG" = "true" ]; then
	$@
    fi
}
a=1
DEBUG echo "a=$a"
if [ "$a" -eq 1 ]
then
	b=2
else
	b=1
fi
DEBUG echo "b=$b"
c=3
DEBUG echo "c=$c"
